<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ajax文件上传</title>
    <script src="jquery-3.4.1.min.js"></script>
</head>
<body>
<input type="file" id="file">
<input type="button" value="上传" onclick="upload()">
<div id="url"></div>
</body>
<script>
    function upload() {
        var file = $("#file")[0].files[0];
        var formData = new FormData();
        formData.append("file", file);
        $.ajax({
            type:'post',
            url:'upload',
            processData:false,
            contentType:false,
            data:formData,
            success: function (data) {
                $("#url").html(data)
            }
        })

    }
</script>
</html>